import constObj from '../../unit/const.js';
let {
	i18n,
	lan
} = constObj;

let defaultPos = "right";
let buttons = [{
	name: "rotate",
	color: "blue",
	size: "s1",
	positionType: defaultPos,
	label: i18n.rotation[lan],
	arrow: "translate(0, 63px)",
	position: true,
}, {
	name: "down",
	color: "blue",
	size: "s1",
	positionType: defaultPos,
	label: i18n.down[lan],
	arrow: "translate(0,-71px) rotate(180deg)",
	position: false,
}, {
	name: "left",
	color: "blue",
	size: "s1",
	positionType: defaultPos,
	label: i18n.left[lan],
	arrow: "translate(60px, -12px) rotate(270deg)",
	position: false,
}, {
	name: "right",
	color: "blue",
	size: "s1",
	positionType: defaultPos,
	label: i18n.right[lan],
	arrow: "translate(-60px, -12px) rotate(90deg)",
	position: false,
}, {
	name: "drop",
	color: "blue",
	size: "s0",
	positionType: defaultPos,
	label: `${i18n.drop[lan]} (SPACE)`,
	arrow: "",
	position: false,
}, {
	name: "reset",
	color: "red",
	size: "s2",
	positionType: defaultPos,
	label: `${i18n.reset[lan]}(R)`,
	arrow: "",
	position: false,
}, {
	name: "music",
	color: "green",
	size: "s2",
	positionType: defaultPos,
	label: `${i18n.sound[lan]}(S)`,
	arrow: "",
	position: false,
}, {
	name: "pause",
	color: "green",
	size: "s2",
	positionType: defaultPos,
	label: `${i18n.pause[lan]}(P)`,
	arrow: "",
	position: false,
}, {
	name: "exchange",
	color: "green",
	size: "s2",
	positionType: defaultPos,
	label: `${i18n.exchange[lan]}(E)`,
	arrow: "",
	position: false,
}, {
	name: "helper",
	color: "green",
	size: "s2",
	positionType: defaultPos,
	label: `${i18n.help[lan]}(H)`,
	arrow: "",
	position: false,
}];
let positions = {
	right: {
		rotate: {
			top: 0,
			left: 374,
		},
		down: {
			top: 180,
			left: 374,
		},
		left: {
			top: 90,
			left: 284,
		},
		right: {
			top: 90,
			left: 464,
		},
		drop: {
			top: 100,
			left: 52,
		},
		reset: {
			top: 0,
			left: 210,
		},
		music: {
			top: 0,
			left: 130,
		},
		pause: {
			top: 0,
			left: 50,
		},
		exchange: {
			top: -60,
			left: 540,
		},
		helper: {
			top: -60,
			left: -10,
		}
	},
	left: {
		rotate: {
			top: 0,
			left: 95,
		},
		down: {
			top: 180,
			left: 95,
		},
		left: {
			top: 90,
			left: 5,
		},
		right: {
			top: 90,
			left: 185,
		},
		drop: {
			top: 100,
			left: 380,
		},
		reset: {
			top: 0,
			left: 480,
		},
		music: {
			top: 0,
			left: 400,
		},
		pause: {
			top: 0,
			left: 320,
		},
		exchange: {
			top: -60,
			left: 540,
		},
		helper: {
			top: -60,
			left: -10,
		}
	}
};



function exchange(buttons) {
	buttons.forEach((bt) => {
		let p = bt.positionType == "right" ? "left" : "right";
		bt.top = positions[p][bt.name].top;
		bt.left = positions[p][bt.name].left;
		bt.positionType = p;
	});
	return buttons;
}

export default {
	state: exchange(buttons),
	buttons(state) {
		state.buttons = exchange(state.buttons);
	}
};
